<?php
include "../include/db.php";
// get task
if(isset($_GET['task'])) { $task = $_GET['task']; } 
else if(isset($_POST['task'])) { $task = $_POST['task']; }

// get view
if(isset($_GET['view'])) { $view = $_GET['view']; } 
else if(isset($_POST['view'])) { $view = $_POST['view']; }
else { $view = ""; }

// get page
if(isset($_GET['p'])) { $p = $_GET['p']; } 
else if(isset($_POST['p'])) { $p = $_POST['p']; }
else { $p = 1; }

// get search
if(isset($_GET['search'])) { $search = $_GET['search']; } 
else if(isset($_POST['search'])) { $search = $_POST['search']; }
else { $search = ""; }



// connect to db
mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());

// get marker totals
$total_approved = mysql_num_rows(mysql_query("SELECT id FROM places WHERE approved='1' AND id_user='$id_user' "));
$total_rejected = mysql_num_rows(mysql_query("SELECT id FROM places WHERE approved='0' AND id_user='$id_user' "));
$total_pending = mysql_num_rows(mysql_query("SELECT id FROM places WHERE approved='2' AND id_user='$id_user' "));
$total_all = mysql_num_rows(mysql_query("SELECT id FROM places WHERE id_user='$id_user'"));

// admin header
$admin_head = "
  <html>
  <head>
    <title>La web de las protestas</title>
    <meta name='viewport' content='width=device-width, initial-scale=1.0, user-scalable=no'>
    <meta http-equiv='content-type' content='text/html; charset=UTF-8' />
    <link href='../bootstrap/css/bootstrap.css' rel='stylesheet' type='text/css' />
    <link href='../bootstrap/css/bootstrap-responsive.css' rel='stylesheet' type='text/css' />
    <link rel='stylesheet' href='admin.css' type='text/css' />
    <script src='../bootstrap/js/bootstrap.js' type='text/javascript' charset='utf-8'></script>
    <script src='../scripts/jquery-1.7.1.js' type='text/javascript' charset='utf-8'></script>

<script type=\"text/javascript\">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-38378176-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
  </head>
  <body>
";
if($page != "login") {
  $admin_head .= "
    <div class='navbar navbar-fixed-top'>
      <div class='navbar-inner'>
        <div class='container'>
          <a class='brand' href='admin.php'>
            Administración de Protestas
          </a>
          <ul class='nav'>
            <li"; if($view == "") { $admin_head .= " class='active'"; } $admin_head .= ">
              <a href='admin.php'>Todas</a>
            </li>
            <li"; if($view == "approved") { $admin_head .= " class='active'"; } $admin_head .= ">
              <a href='admin.php?view=approved'>
                Aprobadas
                <span class='badge badge-info'>$total_approved</span>
              </a>
            </li>
            <li"; if($view == "pending") { $admin_head .= " class='active'"; } $admin_head .= ">
              <a href='admin.php?view=pending'>
                Pendientes
                <span class='badge badge-info'>$total_pending</span>
              </a>
            </li>
            <li"; if($view == "rejected") { $admin_head .= " class='active'"; } $admin_head .= ">
              <a href='admin.php?view=rejected'>
                Rechazadas
                <span class='badge badge-info'>$total_rejected</span>
              </a>
            </li>
          </ul>
          <form class='navbar-search pull-left' action='admin.php' method='get'>
            <input type='text' name='search' class='search-query' placeholder='Buscar' autocomplete='off' value='$search'>
          </form>
          <ul class='nav pull-right'>
            <li><a href='../index.php'>Volver al Mapa</a></li>
          </ul>
        </div>
      </div>
    </div>
  ";
}
$admin_head .= "
  <div id='content'>
";

// admin footer 
$admin_foot = "
    </div>
  </body>
</html>
";

?>